﻿<template>
	<transition name="el-zoom-in-center">
		<div class="JNPF-preview-main">
			<div class="JNPF-common-page-header">
				<el-page-header @back="goBack" :content="!dataForm.id ? '新建' : isDetail ? '详情' : '编辑'"/>
				<div class="options">
					<el-button type="primary" @click="dataFormSubmit()" v-if="!isDetail">确 定</el-button>
					<el-button @click="goBack">取 消</el-button>
				</div>
			</div>
			<el-row :gutter="15"  class="main" :style="{margin: '0 auto',width:'100%'}">
				<el-form ref="elForm" :model="dataForm" size="medium" label-width="115px" label-position="right" :disabled="!!isDetail" :rules="rules">
					<el-col :span="12" >
						<el-form-item label="登记人" prop="creatorUserId">
							<el-input v-model="dataForm.creatorUserId" placeholder="系统自动生成" readonly >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="12" >
						<el-form-item label="登记时间" prop="creatorTime">
							<el-input v-model="dataForm.creatorTime" placeholder="系统自动生成" readonly >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="24" >
						<el-form-item label="登记单号" prop="autoNo">
							<el-input v-model="dataForm.autoNo" placeholder="系统自动生成" readonly >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="12" >
						<el-form-item label="资产名称" prop="fullName">
							<el-input v-model="dataForm.fullName" placeholder="请输入" clearable required :style='{"width":"100%"}' >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="12" >
						<el-form-item label="资产编号" prop="enCode">
							<el-input v-model="dataForm.enCode" placeholder="请输入" clearable required :style='{"width":"100%"}' >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="12" >
						<el-form-item label="资产类型" prop="capitalType">
							<el-select v-model="dataForm.capitalType" placeholder="请选择" clearable required :style='{"width":"100%"}' >
								<el-option v-for="(item, index) in capitalTypeOptions" :key="index" :label="item.fullName" :value="item.id" ></el-option>
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="12" >
						<el-form-item label="使用期限" prop="duration">
							<el-input-number v-model="dataForm.duration" placeholder="数字文本" required :step="1" controls-position="right" >
							</el-input-number>月
						</el-form-item>
					</el-col>
					<el-col :span="12" >
						<el-form-item label="生产日期" prop="productionDate">
							<el-date-picker v-model="dataForm.productionDate" placeholder="请选择" clearable required :style='{"width":"100%"}' type='date' format="yyyy-MM-dd" value-format="timestamp" >
							</el-date-picker>
						</el-form-item>
					</el-col>
					<el-col :span="12" >
						<el-form-item label="到期时间" prop="endDate">
							<el-date-picker v-model="dataForm.endDate" placeholder="请选择" clearable :style='{"width":"100%"}' type='date' format="yyyy-MM-dd" value-format="timestamp" >
							</el-date-picker>
						</el-form-item>
					</el-col>
					<el-col :span="12" >
						<el-form-item label="产品价格" prop="price">
							<el-input-number v-model="dataForm.price" placeholder="数字文本" required :step="100" :precision="2">
							</el-input-number>元
						</el-form-item>
					</el-col>
					<el-col :span="12" >
						<el-form-item label="预计价值" prop="planAmount">
							<el-input-number v-model="dataForm.planAmount" placeholder="数字文本" :step="100" :precision="2">
							</el-input-number>元
						</el-form-item>
					</el-col>
					<el-col :span="12" >
						<el-form-item label="管理员" prop="admin">
							<user-select v-model="dataForm.admin" placeholder="请选择" required >
							</user-select>
						</el-form-item>
					</el-col>
					<el-col :span="12" >
						<el-form-item label="使用部门" prop="useOrganize">
							<dep-select v-model="dataForm.useOrganize" placeholder="请选择" required >
							</dep-select>
						</el-form-item>
					</el-col>
					<el-col :span="24" >
						<el-form-item label="使用人员" prop="useUser">
							<user-select v-model="dataForm.useUser" placeholder="请选择" required multiple >
							</user-select>
						</el-form-item>
					</el-col>
					<el-col :span="24" >
						<el-form-item label="资产描述" prop="description">
							<el-input v-model="dataForm.description" placeholder="请输入" clearable :style='{"width":"100%"}' >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="24" >
						<el-form-item label="资产图片" prop="photo">
							<JNPF-UploadImg v-model="dataForm.photo" :fileSize="2" sizeUnit="MB" :limit="9" >
							</JNPF-UploadImg>
						</el-form-item>
					</el-col>
					<el-col :span="24" >
						<el-form-item label="备注" prop="remark">
							<el-input v-model="dataForm.remark" placeholder="请输入" show-word-limit :style='{"width":"100%"}' type='textarea' :autosize='{"minRows":4,"maxRows":4}' >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="12" v-if="false" >
						<el-form-item label="修改人" prop="lastModifyUserId">
							<el-input v-model="dataForm.lastModifyUserId" placeholder="系统自动生成" readonly >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="12" v-if="false" >
						<el-form-item label="修改时间" prop="lastModifyTime">
							<el-input v-model="dataForm.lastModifyTime" placeholder="系统自动生成" readonly >
							</el-input>
						</el-form-item>
					</el-col>
				</el-form>
			</el-row>
		</div>
	</transition>
</template>
<script>
	import request from '@/utils/request'
	import { getDictionaryDataSelector } from '@/api/systemData/dictionary'
	import { previewDataInterface } from '@/api/systemData/dataInterface'
	export default {
		components: {},
		props: [],
		data() {
			return {
				loading: false,
				visible: false,
				isDetail: false,
				dataForm: {
					creatorUserId:undefined,
					creatorTime:undefined,
					autoNo:undefined,
					fullName:undefined,
					enCode:undefined,
					capitalType:undefined,
					duration:0,
					productionDate:undefined,
					endDate:undefined,
					price:0,
					planAmount:0,
					admin:undefined,
					useOrganize:undefined,
					useUser:undefined,
					description:undefined,
					photo:[],
					remark:undefined,
					lastModifyUserId:undefined,
					lastModifyTime:undefined,
				},
				rules: {
					fullName:[
						{
							required:true,
							message:'请输入资产名称',
							trigger:'blur'
						},
					],
					enCode:[
						{
							required:true,
							message:'请输入资产编号',
							trigger:'blur'
						},
					],
					capitalType:[
						{
							required:true,
							message:'请输入资产类型',
							trigger:'change'
						},
					],
					duration:[
						{
							required:true,
							message:'请输入使用期限',
							trigger:["blur","change"]
						},
					],
					productionDate:[
						{
							required:true,
							message:'请输入生产日期',
							trigger:'change'
						},
					],
					price:[
						{
							required:true,
							message:'请输入产品价格',
							trigger:["blur","change"]
						},
					],
					admin:[
						{
							required:true,
							message:'请输入管理员',
							trigger:'change'
						},
					],
					useOrganize:[
						{
							required:true,
							message:'请输入使用部门',
							trigger:'change'
						},
					],
					useUser:[
						{
							required:true,
							message:'请输入使用人员',
							trigger:'change'
						},
					],
				},
				capitalTypeOptions : [],
			}
		},
		computed: {},
        watch: {},
        created() {
			this.getcapitalTypeOptions();
		},
		mounted() {
        },
		methods: {
			getcapitalTypeOptions(){
				getDictionaryDataSelector('857693019fd047eeabd294b07a414740').then(res => {
					this.capitalTypeOptions = res.data.list
				});
			},
			goBack() {
                this.$emit('refresh')
            },
			init(id, isDetail) {
				this.dataForm.id = id || 0;
                this.visible = true;
                this.isDetail = isDetail || false;
				this.$nextTick(() => {
					this.$refs['elForm'].resetFields();
					if (this.dataForm.id) {
						request({
							url: '/api/SubDev/ZyOaCapital/' + this.dataForm.id,
							method: 'get'
						}).then(res =>{
							this.dataForm = res.data;
						})
					}
				})
			},
			dataFormSubmit() {
				this.$refs['elForm'].validate((valid) => {
                    if (valid) {
                        if (!this.dataForm.id) {
                            request({
                                url: `/api/SubDev/ZyOaCapital`,
                                method: 'post',
                                data: this.dataForm,
                            }).then((res) => {
                                this.$message({
                                    message: res.msg,
                                    type: 'success',
                                    duration: 1000,
                                    onClose: () => {
                                        this.visible = false,
                                            this.$emit('refresh', true)
                                    }
                                })
                            })
                        } else {
                            request({
                                url: '/api/SubDev/ZyOaCapital/' + this.dataForm.id,
                                method: 'PUT',
                                data: this.dataForm
                            }).then((res) => {
                                this.$message({
                                    message: res.msg,
                                    type: 'success',
                                    duration: 1000,
                                    onClose: () => {
                                        this.visible = false
                                        this.$emit('refresh', true)
                                    }
                                })
                            })
                        }
                    }
                })
			},
		}
	}
</script>
